##############################################################################
# Filename: Analysis_ArticleEvaluation_MCQ.R
# Purpose: Produce Table 1 & Figure 2 in main text
##############################################################################

source("Setup.R")

### Table 1:  Effect of article read and level of BJP support 
          #   on indicators of article quality
mod_correct_main = lm(YesCorrect ~ ProBJP*Article + CollegeGrad + NewsDaily + StrongInterestPolitics, data = data_eval)
mod_ww_main = lm(YesWellWritten ~ ProBJP*Article + CollegeGrad + NewsDaily + StrongInterestPolitics, data = data_eval)
mod_recm_main = lm(YesRecommend ~ ProBJP*Article + CollegeGrad + NewsDaily + StrongInterestPolitics, data = data_eval)
stargazer(mod_correct_main, mod_ww_main, mod_recm_main,
          align=TRUE, keep.stat="n", no.space=TRUE,
          se = starprep(mod_correct_main, mod_ww_main, mod_recm_main),
          dep.var.labels=c("Correct", "Well-Written","Recommend"),
          covariate.labels=c("Pro-BJP","Positive Article",
                             "College Graduate", "Daily News", "Interested in Politics",
                             "Pro-BJP x Positive Article"))
rm(mod_correct_main, mod_ww_main, mod_recm_main)


### Figure 2: Relationships between level of BJP support and article quality indicators 
           #  by article
 ## (& in-text references to predicted probabilities)
mod_correct_int = lm(YesCorrect ~ ProBJP*Article, data = data_eval)
mod_ww_int = lm(YesWellWritten ~ ProBJP*Article, data = data_eval)
mod_recm_int = lm(YesRecommend ~ ProBJP*Article, data = data_eval)

## Correct
predprob = ggpredict(mod_correct_int, c("ProBJP","Article"))
predprob
ggplot(data = predprob, aes(x = x, y = predicted, group = group, col = group, shape = group)) +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.03) +
  geom_line(aes(color = group)) +
  geom_point(size = 2) +
  labs(x = "Pro-BJP", y = "Predicted Probability", title = "Correct") +
  scale_color_manual(values = c("darkblue","darkgreen"), labels = c("Negative Article", "Positive Article"), name = "") +
  scale_shape_manual(values = c(15,16), labels = c("Negative Article", "Positive Article"), name = "") +
  scale_y_continuous(expand = c(0,0), limits = c(0,1), breaks = (seq(0,1,0.20))) +
  scale_x_discrete(expand = c(0.2,0), labels = c("0", "1")) +
  coord_fixed(ratio = 1.0) +
  theme_bw() + theme_minimal() +
  theme(plot.title = element_text(family = "sans", size=13, hjust=0.5),
        axis.title = element_text(family = "sans", size=11),
        axis.text.x = element_text(family = "sans", size=10),
        legend.position= "bottom",
        plot.background = element_rect(fill="white",color="white"))
# ggsave("plot_int_Correct.png", width = 4, height = 4)

## Well written
predprob = ggpredict(mod_ww_int, c("ProBJP","Article"))
predprob
ggplot(data = predprob, aes(x = x, y = predicted, group = group, col = group, shape = group)) +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.03) +
  geom_line(aes(color = group)) +
  geom_point(size = 2) +
  labs(x = "Pro-BJP", y = "Predicted Probability", title = "Well-Written") +
  scale_color_manual(values = c("darkblue","darkgreen"), labels = c("Negative Article", "Positive Article"), name = "") +
  scale_shape_manual(values = c(15,16), labels = c("Negative Article", "Positive Article"), name = "") +
  scale_y_continuous(expand = c(0,0), limits = c(0,1), breaks = (seq(0,1,0.20))) +
  scale_x_discrete(expand = c(0.2,0), labels = c("0", "1")) +
  coord_fixed(ratio = 1.0) +
  theme_bw() + theme_minimal() +
  theme(plot.title = element_text(family = "sans", size=13, hjust=0.5),
        axis.title = element_text(family = "sans", size=11),
        axis.text.x = element_text(family = "sans", size=10),
        legend.position= "bottom",
        plot.background = element_rect(fill="white",color="white"))
# ggsave("plot_int_WW.png", width = 4, height = 4)

## Recommend
predprob = ggpredict(mod_recm_int, c("ProBJP","Article"))
predprob
ggplot(data = predprob, aes(x = x, y = predicted, group = group, col = group, shape = group)) +
  geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.03) +
  geom_line(aes(color = group)) +
  geom_point(size = 2) +
  labs(x = "Pro-BJP", y = "Predicted Probability", title = "Recommend") +
  scale_color_manual(values = c("darkblue","darkgreen"), labels = c("Negative Article", "Positive Article"), name = "") +
  scale_shape_manual(values = c(15,16), labels = c("Negative Article", "Positive Article"), name = "") +
  scale_y_continuous(expand = c(0,0), limits = c(0,1), breaks = (seq(0,1,0.20))) +
  scale_x_discrete(expand = c(0.2,0), labels = c("0", "1")) +
  coord_fixed(ratio = 1.0) +
  theme_bw() + theme_minimal() +
  theme(plot.title = element_text(family = "sans", size=13, hjust=0.5),
        axis.title = element_text(family = "sans", size=11),
        axis.text.x = element_text(family = "sans", size=10),
        legend.position= "bottom",
        plot.background = element_rect(fill="white",color="white"))
# ggsave("plot_int_Recm.png", width = 4, height = 4)

rm(mod_correct_int, mod_recm_int, mod_ww_int,predprob)